#!/bin/bash
PID="/var/run/proxy.pid"
NAME="proxy"
case "$1" in 
start)
   if [ -e ${PID} ]; then
      echo ${NAME} is running, pid=`cat ${PID}`, please stop first
      exit 1
   else
      monexec run -w /etc/proxy -- proxy >/dev/null 2>&1 &
      echo $!>${PID}
   fi
   ;;
stop)
   if [ -e ${PID} ]; then
      kill `cat ${PID}`
      rm ${PID}
   fi
   ;;
restart)
   $0 stop
   $0 start
   ;;
status)
   if [ -e ${PID} ]; then
      echo ${NAME} is running, pid=`cat ${PID}`
   else
      echo ${NAME} is NOT running
      exit 1
   fi
   ;;
*)
   echo "Usage: $0 {start|stop|status|restart}"
esac

exit 0 